import {Button} from "antd";
import {IFile} from "@/api/file.ts";
import useDownload from "@/hooks/useDownload.ts";

interface IProps {
    getDataList: () => Array<IFile>
    selectFileUID: Array<string>
}

const BatchDownload = ({ getDataList, selectFileUID }: IProps) => {
    const { batchDownload } = useDownload()
    const download = async () => {
        const data = getDataList().filter(item => selectFileUID.includes(item.fileUID)).map(item => ({ path: item.path, fileName: item.fileName }))
        await batchDownload(data)
    }
    return <Button disabled={selectFileUID.length === 0 || (getDataList() && getDataList().some((item: IFile) => selectFileUID.includes(item.fileUID) && item.type === 'folder'))} onClick={download}>批量下载</Button>
}

export default BatchDownload